package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Constitution;
import com.ruoyi.system.service.IConstitutionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 体质信息Controller
 * 
 * @author ruoyi
 * @date 2023-11-25
 */
@RestController
@RequestMapping("/system/constitution")
public class ConstitutionController extends BaseController
{
    @Autowired
    private IConstitutionService constitutionService;

    /**
     * 查询体质信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:constitution:list')")
    @GetMapping("/list")
    public TableDataInfo list(Constitution constitution)
    {
        startPage();
        List<Constitution> list = constitutionService.selectConstitutionList(constitution);
        return getDataTable(list);
    }

    /**
     * 导出体质信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:constitution:export')")
    @Log(title = "体质信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Constitution constitution)
    {
        List<Constitution> list = constitutionService.selectConstitutionList(constitution);
        ExcelUtil<Constitution> util = new ExcelUtil<Constitution>(Constitution.class);
        util.exportExcel(response, list, "体质信息数据");
    }

    /**
     * 获取体质信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:constitution:query')")
    @GetMapping(value = "/{constitutionId}")
    public AjaxResult getInfo(@PathVariable("constitutionId") Long constitutionId)
    {
        return success(constitutionService.selectConstitutionByConstitutionId(constitutionId));
    }

    /**
     * 新增体质信息
     */
    @PreAuthorize("@ss.hasPermi('system:constitution:add')")
    @Log(title = "体质信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Constitution constitution)
    {
        return toAjax(constitutionService.insertConstitution(constitution));
    }

    /**
     * 修改体质信息
     */
    @PreAuthorize("@ss.hasPermi('system:constitution:edit')")
    @Log(title = "体质信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Constitution constitution)
    {
        return toAjax(constitutionService.updateConstitution(constitution));
    }

    /**
     * 删除体质信息
     */
    @PreAuthorize("@ss.hasPermi('system:constitution:remove')")
    @Log(title = "体质信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{constitutionIds}")
    public AjaxResult remove(@PathVariable Long[] constitutionIds)
    {
        return toAjax(constitutionService.deleteConstitutionByConstitutionIds(constitutionIds));
    }
}
